home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / SNR40.ARJ / SNR.DOC < prev    next >
Text File  |  1991-01-08  |  18KB  |  373 lines

  1. TITLE:         SNR.EXE             VERSION: 4.0
  2.  
  3. PURPOSE:       Multiple simultaneous Search 'N' Replace program
  4.  
  5. DATE:          7/19/90
  6.  
  7. AUTHOR:        THOMAS A. LUNDIN
  8.                16267 Hudson Avenue
  9.                Lakeville, MN 55044
  10.                day phone: (612) 588-7571
  11.  
  12. DONATION:      $25 requested
  13.  
  14. DESCRIPTION:   SNR is a multi-string search-and-replace filter. Both 
  15.                text and binary files can be processed by the program, 
  16.                since SNR allows the definition of hex values in a 
  17.                search-and-replace equation. SNR will translate a file of 
  18.                any size that your system can handle (I've used it on 
  19.                50-megabyte files).
  20.                
  21.                Up to 50 multi-character (m:n) equations can be entered into 
  22.                an SNR table, each of which can be a maximum of 200 
  23.                characters in length. Additionally, up to 256 
  24.                single-character (1:1) equations can be loaded into an SNR 
  25.                table. All search-and-replace operations are performed in a 
  26.                single pass. NEW! Context flag allows toggling between two 
  27.                different output strings for the same input string.
  28.                
  29.                See the note on BIT STRIPPING, further on.
  30.  
  31. REVISION       4.0 - 7/19/90
  32. HISTORY:       Removed OS/2 compatibility. Nobody used it. Allow 256 1:1 
  33.                equations to be loaded in addition to 50 m:n equations. 
  34.                Added context flag.
  35.  
  36.                3.01 - 11/3/89
  37.                Program recompiled for family mode, meaning it will run 
  38.                as-is under DOS, OS/2 real mode, and OS/2 protected mode.
  39.  
  40.                Also improved I/O throughput on fast disk drives.
  41.  
  42.                3.0 - 9/27/89
  43.                The program has been completely rewritten. The pesky bugs
  44.                that were present in versions 1.5 and 2.0 have been 
  45.                eliminated.
  46.  
  47.                All binary characters INCLUDING NULLS can now be searched 
  48.                and replaced. Nulls can also be entered as part of a 
  49.                larger search-and-replace equation.
  50.  
  51.                An automatic "bit-stripping" feature has been added which
  52.                removes the high-order bits from input characters, 
  53.                forcing 8-bit codes into 7-bit ASCII. 
  54.                -------------THIS IS NOW THE DEFAULT ACTION!!!------------
  55.                The feature can be selectively disabled for binary files 
  56.                (see BIT STRIPPING, below).
  57.  
  58.                The equation length has been increased to 200 characters, 
  59.                which can be split into search and replace sides of any 
  60.                length, as long as the total does not exceed 200.
  61.  
  62.                Equations no longer need to be in any specific order.
  63.  
  64.                The average speed of the program has been vastly 
  65.                improved, especially for multiple and high-occurrence 
  66.                search and replaces.
  67.  
  68.                The program no longer needs to read itself for runtime 
  69.                parameters.
  70.  
  71. OPERATION:     The command line invocation is:
  72.  
  73.                snr [@]filename ext tablename [/d] ─┘
  74.  
  75.                1.   "filename" is any unambiguous DOS path/file name. An 
  76.                     optional at-sign (@) in front of the filename indicates 
  77.                     that multiple files are to be processed from a directory 
  78.                     list file, i.e., a file that has been created from a 
  79.                     redirected DIR command. For example, the DOS command 
  80.  
  81.                     dir *.txt >dirfile  ─┘
  82.  
  83.                     will create a disk file named "dirfile" which contains a 
  84.                     directory of all files with a ".TXT" extension.
  85.  
  86.                2.   "ext" is the filename extension you wish to assign each 
  87.                     output file. The output files are created using the name 
  88.                     of the input file plus the extension specified here. The 
  89.                     choice of an extension is important; if you accidentally 
  90.                     choose an extension which is already used by an input 
  91.                     file, the result of the process is indeterminable, 
  92.                     although file data loss is likely to occur. Use an 
  93.                     extension which is sure to be unique.
  94.  
  95.                     Extensions can be the DOS device names CON, NUL, 
  96.                     AUX, and PRN. In any of these four cases, an output 
  97.                     file is NOT created on disk; rather, the output is 
  98.                     redirected to the console (CON), nowhere (NUL), the 
  99.                     rs232 port (AUX), or the printer (PRN). Using CON is 
  100.                     handy for a quick preview of the conversion process 
  101.                     before storing it to disk.
  102.  
  103.                     NOTE: If you preview converted binary files to CON, 
  104.                     be aware that hex code 1A (DOS end-of-file) will 
  105.                     terminate the conversion display, perhaps 
  106.                     prematurely. This permature termination will NOT 
  107.                     occur when you store to disk.
  108.  
  109.                3.   "tablename" is the unambiguous DOS path/file name which 
  110.                     contains the string translation "equations". Although no 
  111.                     restrictions are placed upon the tablename, for sake of 
  112.                     clarity it is suggested that you adopt a consistent naming 
  113.                     scheme for them, (say, with an *.SNR extension). Tables 
  114.                     are discussed in more detail below. 
  115.  
  116.                4.   "/d" is an option which replaces the original input file 
  117.                     with the converted data. The EXT specified on the 
  118.                     command line is thus used temporarily until the conversion 
  119.                     is complete, at which time the program performs an 
  120.                     internal file delete/rename operation. 
  121.  
  122.                EXAMPLES...
  123.  
  124.                C>snr tstfil.doc txt tst.snr ─┘
  125.  
  126.                The above command line will process the input file 
  127.                "tstfil.doc" and create an output file "tstfil.txt" using 
  128.                the table "tst.snr". 
  129.  
  130.                C>snr @dirlist p1 sample.snr ─┘
  131.  
  132.                The above command line will process a group of files 
  133.                contained in the directory list "dirlist" and create a 
  134.                group of output files with extensions of *.p1 using the 
  135.                table "sample.snr".
  136.  
  137. CONVERSION     SNR tables are ASCII text files which contain the 
  138. TABLES:        search-and-replace equations used by the program. Up to 306 
  139.                of these equations can be entered in a single table -- 256 
  140.                1:1 equations, and 50 m:n equations. The m:n equations can 
  141.                consist of 200 characters split freely between the search 
  142.                side and the replacement side. Blank lines in a table will 
  143.                be ignored.
  144.                
  145.                A sample 1:1 equation would be:
  146.                
  147.                     A=a
  148.                     
  149.                The above equation would translate an upper-case 'A' to a 
  150.                lower-case 'a'.
  151.  
  152.                A sample m:n equation would be:
  153.                
  154.                     Now is the time=NOW IS THE TIME
  155.  
  156.                The above equation will translate the words "Now is the 
  157.                time" to all upper-case. Notice that spaces ARE SIGNIFICANT 
  158.                characters in an equation. 
  159.                
  160.                An equation can be defined to ignore search text (that is, 
  161.                throw it away on output) simply by leaving out a replacement 
  162.                string, like this:
  163.  
  164.                     Now is the time=
  165.  
  166.                If you want to output word spaces at the end of a 
  167.                replacement string, but your text editor strips trailing 
  168.                spaces, you can define them as hex codes:
  169.  
  170.                     Now is the time =NOW IS THE TIME\20
  171.  
  172.                In fact, any hex code can be formed from a backslash 
  173.                followed by two hex digits (0-9, a-f, A-F). You'd normally 
  174.                use hex codes to search or replace binary characters that 
  175.                can't be generated directly from the keyboard. For instance, 
  176.                a carriage return/line feed sequence (CRLF) can be specified 
  177.                like this: 
  178.  
  179.                     \0d\0a\0d\0a=\0d\0a
  180.  
  181.                The above equation will convert two CRLFs in a row to a 
  182.                single CRLF.
  183.  
  184.                There are three ASCII characters which MUST be specified as 
  185.                hex codes in an SNR equation, since they have special 
  186.                meaning in their normal ASCII form. They are:
  187.                
  188.                Backslash (\), which must be entered as \5c
  189.                Equals (=), which must be entered as \3d
  190.                Asterisk (*), which must be entered as \2a
  191.  
  192.                The end of a table is signified by a \\E on a line by itself. 
  193.                This code is optional, but recommended, since it will prevent 
  194.                the table processor from inadvertently reading past the end of 
  195.                your equations (some word processors may pad their last blocks 
  196.                with garbage, which the table processor would attempt to read 
  197.                as equation data). 
  198.  
  199.                SNR provides for comments in its tables. Comments can be 
  200.                entered in a table as lines by themselves, or set off from 
  201.                an equation:
  202.  
  203.                \    This is a comment line by itself.
  204.                \    A comment consists of a single backslash
  205.                \    followed by one or more spaces.
  206.  
  207.                \0d\0a=\0d\0a  \ this will ensure that existing CRLF pairs are
  208.                               \ left untouched
  209.                \0d=\0d\0a     \ this equation will convert an isolated CR 
  210.                               \ into a CRLF
  211.                \0a=\0d\0a     \ this equation will convert an isolated LF
  212.                               \ into a CRLF
  213.  
  214.                \\E
  215.  
  216.                If you're a programmer, or you've used a macro language of 
  217.                some kind, you know the value of program comments. If you're 
  218.                new to the field of user programming, get into the habit of 
  219.                commenting your work. Believe me, you'll be glad you did.
  220.                
  221.                SNR will automatically sort equations by length when 
  222.                assembling a table in memory. SNR does not perform a 
  223.                sequential search of equations, so the order in which you 
  224.                enter your equations is immaterial.
  225.                               
  226.                There is a provision to load 256 equations that have one 
  227.                character to search for, and one character to replace with 
  228.                (1:1). This greater capacity is available to allow you to 
  229.                develop equations that can translate a file's entire codeset 
  230.                (for instance, from ASCII to EBCDIC or vice versa). See the 
  231.                sample tables ASC2EBC.SNR and EBC2ASC.SNR for examples of 
  232.                tables that use 1:1 equations. 
  233.  
  234. CONTEXT FLAG:  There are probably instances where you'd like to toggle 
  235.                between two different replacement strings for the same 
  236.                search string. The context flag allows you to do this. Some 
  237.                example uses would be:
  238.                
  239.                - to compress multiple spaces from a document
  240.                - to ignore any text between two codes
  241.                - to make one code alternate as two different codes
  242.                - to turn all-upper-case text into upper and lower
  243.                
  244.                ...and many other uses.
  245.                
  246.                The context flag has two states: on or off. (When SNR begins 
  247.                execution, the context flag's state is OFF). The flag's 
  248.                state can be tested in a search, and its state can be set or 
  249.                reset in a replacement. The "off" state of the context flag 
  250.                is entered as *00. The "on" state is entered as *01. The 
  251.                context flag is the last item entered in a search or 
  252.                replacement string. For example:
  253.                
  254.                     ABC*00=abc*01
  255.                     ABC*01=XYZ*00
  256.                
  257.                In the above two equations, if the string "ABC" is read from 
  258.                the input file, and the context flag is OFF, then the string 
  259.                "abc" is written to the output file, and the context flag is 
  260.                set ON. If, on the other hand, the string "ABC" is read from 
  261.                the input file, and the context flag is ON, then the string 
  262.                "XYZ" is written to the output file, and the context flag is 
  263.                reset OFF. For example, if data from the input file looks 
  264.                like this:
  265.                
  266.                ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  267.                
  268.                ...it would convert to this:
  269.                
  270.                abcDEFG XYZDEFG abcDEFG XYZDEFG
  271.  
  272.                Since the context flag is global in scope, you can define 
  273.                many different equations to test and set it in a single 
  274.                table. But beware of unwanted side effects -- remember that 
  275.                only one equation at a time will control the state of the 
  276.                flag, and its state may change between two equations that 
  277.                complement each other, resulting in misconversion. For 
  278.                example:
  279.                
  280.                     ABC*00=abc*01
  281.                     ABC*01=XYZ*00
  282.                     EFG*00=efg*01
  283.                     EFG*01=ZYX*00
  284.                     
  285.                The above equations are similar to the previous example, 
  286.                except that we have defined two new equations that test and 
  287.                set the context flag. Given this example input data:
  288.                
  289.                ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  290.                
  291.                ...the result would convert to this:
  292.                
  293.                abcDZYX abcDZYX abcDZYX abcDZYX
  294.                
  295.                The context flag is being toggled by only two equations:
  296.                
  297.                     ABC*00=abc*01   <--- this one
  298.                     ABC*01=XYZ*00
  299.                     EFG*00=efg*01
  300.                     EFG*01=ZYX*00   <--- and this one
  301.                     
  302.                If, on the other hand, the input data stream looked like 
  303.                this:
  304.                
  305.                ABCDEFG DEFGABC ABCDEFG DEFGABC
  306.                
  307.                ...the result would look like this:
  308.                
  309.                abcDZYX DefgXYZ abcDZYX DefgXYZ
  310.                
  311.                The thing to keep in mind if you are going to use the 
  312.                context flag is: it is OFF when the program begins; you need 
  313.                to enter an equation to set it ON; and then you need to have 
  314.                some equation that resets it OFF.
  315.                
  316.                See some of the sample .SNR tables for examples in the use 
  317.                of the context flag.
  318.  
  319. BIT STRIPPING: SNR's default action is to map all incoming characters to 
  320.                7-bit ASCII before running them through the equations. 
  321.                This is handy if you're converting an old Wordstar file, 
  322.                and don't want to deal individually with the tagged 
  323.                characters.
  324.  
  325.                This action, however, is not at all welcome when you're 
  326.                dealing with files that make use of specific binary 
  327.                characters (examples: Word Perfect, XYWrite, others). In 
  328.                cases where you DON'T want 7-bit mapping to occur, type a 
  329.                \\L8 as the first line of a table; this will disable 
  330.                bit-stripping for that table.
  331.  
  332.                An interesting side-effect of the bit-stripping feature 
  333.                is illustrated by the table STRIP.SNR. It contains NO 
  334.                equations at all (except for the \\E), and yet it will 
  335.                effectively remove the high-order bits from any file that 
  336.                it is run through. Try it!
  337.  
  338. NOTES:         The program will run on any IBM PC/XT/AT series computer 
  339.                using MS-DOS 2.x or higher, with a minimum of 128K RAM.
  340.  
  341.                SNR was compiled with Turbo C++ 2.0, but was written using 
  342.                ANSI C, not C++ (yuk!).
  343.  
  344. DISCLAIMER:    This program is distributed as shareware. Use it, copy 
  345.                it, upload it, give it to your friends. Please distribute 
  346.                only the complete program in ZIP form, including all 
  347.                document and sample files. No warranties, either 
  348.                expressed or implied, are given by the author or 
  349.                distributor of the program, and the user accepts all risk 
  350.                of damage arising out of the application and use of the 
  351.                program. 
  352.  
  353. CONTRIBUTION:  If you like SNR, please mail a contribution of $25 to help 
  354.                defray the cost of developing and supporting the program. 
  355.                At that price, it's one of the bargains of the text 
  356.                processing world, and I'll bet you recoup that investment 
  357.                dozens, maybe hundreds, of times over. Please make checks 
  358.                payable to THOMAS A. LUNDIN and mail to the address shown 
  359.                at the top of this DOC file.
  360.  
  361.                -----------------------------------------------------------
  362.                Send comments/bug reports/contributions to:
  363.  
  364.                          ╔═════════════════════════════╗
  365.                          ║      THOMAS A. LUNDIN       ║
  366.                          ║     16267 Hudson Avenue     ║
  367.                          ║     Lakeville, MN  55044    ║
  368.                          ║   Daytime # (612) 588-7571  ║
  369.                          ╚═════════════════════════════╝
  370.  
  371.                Thank you for using SNR.
  372.  
  373.